extends "../cex___zahuopu-Hide/item.gd"

var data = null
var a = 0
var ItemData = preload("./itemData.gd").getCharaData()

func _init():
	._init()

func init():
	.init()
	name = ItemData.NAME
	type = config.EQUITYPE_EQUI
	attInit()
	price = 30
	info = ItemData.INFO_TEXT_1.format({"0":null})
	info += sys.rndListItem(adlist).format({"0":sys.rndListItem(adcolour),"1":sys.rndListItem(adprice)})

func _connect():
	masCha.connect("onAddItem",self,"_onAddItem")

func _onAddItem(item):
	if Utils.inBattle(masCha):
		yield(sys.get_tree().create_timer(0.05), "timeout")
		data = null
		masCha.delItem(self)
		#sys.newBaseMsg("","{0}".format({"0":ItemData.INFO_TEXT_2}))
		info = ItemData.INFO_TEXT_1.format({"0":null})
		return

	if masCha.lv > 3:
		yield(sys.get_tree().create_timer(0.05), "timeout")
		data = null
		info = ItemData.INFO_TEXT_1.format({"0":null})
		sys.newBaseMsg("",ItemData.INFO_TEXT_3)
		masCha.delItem(self)
		return

	if masCha.id.find("cex") >= 0:
		yield(sys.get_tree().create_timer(0.05), "timeout")
		data = null
		info = ItemData.INFO_TEXT_1.format({"0":null})
		sys.newBaseMsg("",ItemData.INFO_TEXT_3)
		masCha.delItem(self)
		return

	if  masCha.id.find("zahuopu") >= 0 || masCha.id.find("al-merchant") >= 0 || masCha.id.find("XinXiang") >= 0:
		yield(sys.get_tree().create_timer(0.05), "timeout")
		data = null
		info = ItemData.INFO_TEXT_1.format({"0":null})
		sys.newBaseMsg("","{0}".format({"0":ItemData.INFO_TEXT_3}))
		masCha.delItem(self)
		return

	if data == null:
		data = masCha
		info = ItemData.INFO_TEXT_1.format({"0":data.chaName})	

	if data != null && data.id != masCha.id && data.lv == masCha.lv:
		yield(sys.get_tree().create_timer(0.05), "timeout")
		sys.main.player.addCha(sys.main.newChara(masCha.id))
		sys.main.player.addCha(sys.main.newChara(masCha.id))
		var cha = sys.main.evoChara(masCha, data.id)
		cha.isDrag = true
		masCha.delItem(self)
		data = null
		info = ItemData.INFO_TEXT_1.format({"0":null})
		sys.main.player.delItem(self)
		
	if data != null && data.id != masCha.id && data.lv != masCha.lv :
		yield(sys.get_tree().create_timer(0.05), "timeout")
		data = null
		info = ItemData.INFO_TEXT_1.format({"0":null})
		sys.newBaseMsg("",ItemData.INFO_TEXT_4)
		masCha.delItem(self)